﻿using SXFramWork.Core.Quartz;
using SXFramWork.Model;
using SXFramWork.Repository;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace SXFramWork.Quartz
{
    /// <summary>
    /// 任务日志记录
    /// </summary>
    public class TaskLogger : ITaskLogger
    {
        private readonly ISysJobLogRepository _jobLogRepository;
        public TaskLogger(ISysJobLogRepository sysJobLogRepository)
        {
            _jobLogRepository = sysJobLogRepository;
        }

        public string JobId { get; set; }

        public async Task Debug(string msg)
        {
            var entity = new SysJobLogEntity
            {
                SysJobId = JobId,
                Type = 1,
                Message = msg,
                CreateTime = DateTime.Now
            };
            await _jobLogRepository.InsertAsync(entity);
        }

        public async Task Error(string msg)
        {
            //var config = _configProvider.Get<QuartzConfig>();
            //if (!config.Logger)
            //    return;

            var entity = new SysJobLogEntity
            {
                SysJobId = JobId,
                Type = 2,
                Message = msg,
                CreateTime = DateTime.Now
            };
            await _jobLogRepository.InsertAsync(entity);
        }

        public async Task Info(string msg)
        {
            var entity = new SysJobLogEntity
            {
                SysJobId = JobId,
                Type = 0,
                Message = msg,
                CreateTime = DateTime.Now
            };
            await _jobLogRepository.InsertAsync(entity);
        }
    }
}
